# Pull Basic Image
FROM ubuntu:latest

MAINTAINER OpenGMSTeam

# update apt-get source, check to aliyun
RUN \
  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && \
  apt-get clean

# Install supervisord

RUN \
  apt-get update && \
  apt-get install -y supervisor && \
  rm -rf /var/lib/apt/lists/*

COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Install MongoDB and Config
RUN \
  groupadd -r mongodb && useradd -r -g mongodb mongodb && \
  apt-get update && \
  apt-get install -y gnupg && apt-get install -y gnupg1 && apt-get install -y gnupg2 && \
  apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 && \
  echo "deb http://mirrors.aliyun.com/mongodb/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list && \
  apt-get update && \
  apt-get install -y mongodb-org && \
  rm -rf /var/lib/apt/lists/*

# Define mountable directories
VOLUME ["/data/db"]

EXPOSE 27017

# Install wget
RUN \
  apt-get update && apt-get install -y wget && \
  rm -rf /var/lib/apt/lists/*

# Install nodejs
RUN \
  cd /tmp && \
  wget https://nodejs.org/dist/v8.9.3/node-v8.9.3-linux-x64.tar.xz && \
  tar -xvf node-v8.9.3-linux-x64.tar.xz && \
  rm -f node-v8.9.3-linux-x64.tar.xz && \
  mv node-v8.9.3-linux-x64 /usr/local && \
  ln -s /usr/local/node-v8.9.3-linux-x64/bin/node /usr/local/bin/node && \
  ln -s /usr/local/node-v8.9.3-linux-x64/bin/npm /usr/local/bin/npm 

# Install zip and add-apt-repository
RUN \
  apt-get update && apt-get install -y zip && \
  apt-get install -y python-software-properties && \
  apt-get install -y software-properties-common && \
  rm -rf /var/lib/apt/lists/*

# Install JAVA JDK 1.8
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
  
# COPY Project

WORKDIR /usr/src/container

COPY package.json ./

RUN npm install

COPY . /usr/src/container

# Volumes
VOLUME ["/usr/src/container/geo_model", "/usr/src/container/geo_data"]

EXPOSE 3000

CMD ["/usr/bin/supervisord"]


